package com.smh.mianshi.aware;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.stereotype.Component;

/**
 * @author shiminghui
 * @date 2024/10/8 16:27
 * @description: TODO
 */
@Component
public class MyAware implements BeanNameAware, BeanFactoryAware, BeanClassLoaderAware {
    //实现了BeanNameAware接口的类，在bean初始化过程中，会调用setBeanName方法，将bean的id作为参数传入，此时可以获取bean的id，从而做一些业务逻辑处理。
    @Override
    public void setBeanClassLoader(ClassLoader classLoader) {
        System.out.println("classLoader:" + classLoader);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("beanFactory:" + beanFactory);
    }

    @Override
    public void setBeanName(String s) {
        System.out.println("beanName:" + s);
    }
}
